package cn.edu.tju.elm.repository;

import cn.edu.tju.elm.model.Business;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

public interface BusinessRepository extends JpaRepository<Business, Long> {
    List<Business> findAll();
    Optional<Business> findById(Long id);
    // 根据商家名称查询
    List<Business> findByBusinessName(String businessName);

    // 根据商家名称查询（排除指定ID）
    @Query("SELECT b FROM Business b WHERE b.businessName = :businessName AND b.id != :id")
    List<Business> findByBusinessNameAndIdNot(@Param("businessName") String businessName, @Param("id") Long id);

    // 根据名称模糊查询
    List<Business> findByBusinessNameContaining(String name);

    // 根据订单类型查询
    List<Business> findByOrderTypeId(Integer orderTypeId);

    // 根据起送价格范围查询
    List<Business> findByStartPriceLessThanEqual(BigDecimal maxPrice);

    // 检查商家是否存在
    boolean existsById(Long id);
}
